package org.mch.func.str.cut;

import java.awt.event.ActionEvent;

import org.mch.biz.ui.FuncEvent;
import org.mch.biz.ui.FuncPanel;
import org.mch.swingm.core.MFileChooser;

/**
 * 
 * @author mch
 * 
 */
public class ClientEvent extends FuncEvent {
	private static final long serialVersionUID = -9117876453883095101L;

	MFileChooser fileChooser;

	public ClientEvent(FuncPanel panel) {
		super(panel);
	}

	protected void onButtonClick(ActionEvent e) throws Exception {
		if (e.getSource() == getPanel().getBtn_execute_cutindex()) {
			execute_cutindex();
		}
	}

	public void execute_cutindex() {
		String cutindexstr = getPanel().getText_cutindex().getValue();

		String text_left = getPanel().getText_srcstr().getText();
		String[] leftstrs = text_left.split("\n");

		StringBuilder sb = new StringBuilder();
		for (String s : leftstrs) {
			String s1 = s.substring(s.indexOf(cutindexstr) < 0 ? 0 : s.indexOf(cutindexstr), s.length());
			sb.append(s1).append("\n");
		}
		getPanel().getText_newstr().setText(sb.toString());
	}

	public ClientPanel getPanel() {
		return (ClientPanel) super.getPanel();
	}
}